<template>
  <div class="viewcontainer" v-if="dataset">
    <el-dialog
      :title="detailTitle"
      :visible.sync="detailFormVisible"
      width="600px"
      :close-on-click-modal="false"
    >
      <hi-form
        ref="detailForm"
        v-if="detailFormVisible"
        :model="editData"
        :dataSource="dataset"
        v-bind="form"
      ></hi-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>
    <el-row class="view-header">
      <el-col :span="22">
        <hi-lquery
          :target="dataset"
          :columnsTotal="2"
          v-bind="queryPanel"
        ></hi-lquery>
      </el-col>
      <el-col :span="2" style="text-align: right">
        <!-- <el-button type="primary" @click="showAdd">添加</el-button> -->
      </el-col>
    </el-row>
    <el-row class="view-main">
      <el-table
        ref="dataTable"
        :data="dataset.data"
        height="100%"
        style="width: 100%"
        v-loading="dataset.loading"
      >
        <el-table-column type="index" width="50" />
        <el-table-column prop="FDESC" label="门店名称" width="160" />
        <el-table-column prop="FCONTACTMAN" label="联系人" width="160" />
        <el-table-column prop="FTEL" label="电话" width="160" />
        <el-table-column prop="FADDRESS" label="地址" width="180">
          <template slot-scope="scope">
            <div class="text-truncate" :title="scope.row.FADDRESS">
              {{ scope.row.FADDRESS }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="FNOTE" label="备注">
          <template slot-scope="scope">
            <div class="text-truncate" :title="scope.row.FNOTE">
              {{ scope.row.FNOTE }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="FUSERID" label="用户ID" width="100" /> -->
        <el-table-column prop="FCREATEDATE" label="创建日期" width="160" />
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope" v-if="dataset.allowUpdate()">
            <el-button type="text" size="small" @click="showEdit(scope)">
              <i class="el-icon-edit"></i>
            </el-button>
            <!--   <el-button type="text" size="small" @click="remove(scope)">
              <i class="el-icon-delete"></i>
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row class="view-footer pagebar">
      <hi-pagination
        background
        :total="dataset.total"
        :target="dataset"
      ></hi-pagination>
    </el-row>
  </div>
</template>

<script>
import { HiPagination, HiLquery, HiVquery, HiForm } from "hi-ui";
import viewBase from "@/views/base";
import shopDatacfg from "./dataset";
import bankConfig from "../moneyAccount/dataset";
export default {
  name: "shoplist",
  extends: viewBase,
  components: { HiPagination, HiLquery, HiVquery, HiForm },
  data() {
    let datasetCfg = Object.assign({}, shopDatacfg, {
      action: "autoAction",
    });
    return {
      //数据桥梁
      dataBridge: new Map(),
      detailTitle: null,
      //编辑状态
      editstate: "add", //add edit
      editData: {},
      detailFormVisible: false,
      dataset: null,
      //表单配置
      form: {
        columnsTotal: 2,
        items: [
          {
            name: "FIMG",
            label: "门店照片",
            element: "hi-upload",
            props: {
              hideUpload: true,
              "with-credentials": true,
              accept: "image/png, image/jpeg",
              limit: 1,
              // "show-file-list":false,
              // disabled:true,
              multiple: false,
              "list-type": "picture-card",
            },
          },
          {
            name: "FBUSINESSLICENSE",
            label: "营业执照",
            element: "hi-upload",
            props: {
              hideUpload: true,
              "with-credentials": true,
              accept: "image/png, image/jpeg",
              limit: 1,
              // "show-file-list":false,
              // disabled:true,
              multiple: false,
              "list-type": "picture-card",
            },
          },
          {
            name: "FDESC",
            colspan: 2,
          },
          {
            name: "FBANKACCOUNT",
            colspan: 2,
            element: "hi-data-select",
            props: {
              lookup: {
                storeCfg: bankConfig,
                active: true,
                /* treeOption:{
                  "modelFile":"users",
                   label: "name",
                   children: "company"
                   }, */
                multiSelect: false,
                returnFields: {
                  FBANKACCOUNT: "FDESC",
                  FBANKACCOUNTID: "FID",
                },
                columns: [
                  {
                    name: "FDESC",
                    label: "账户名称",
                  },
                  {
                    name: "FBANKDESC",
                    label: "银行名称",
                  },
                  {
                    name: "FBANKID",
                    label: "银行账号",
                  },
                ],
                queryOption: {
                  fields: [
                    {
                      name: "FDESC",
                      label: "账户名称",
                      element: "el-input",
                    },
                  ],
                },
              },
            },
          },
          {
            name: "FCONTACTMAN",
          },
          {
            name: "FTEL",
          },
          {
            name: "FCOORDINATESDESC",
            element: "hi-map-select",
            props: {
              center: {
                // [114.452537,28.112133]
                lng: 114.452537,
                lat: 28.112133,
              },
              zoom: 14,
              lngField: "FEAST",
              latField: "FWEST",
              addressField: "FADDRESS",
              provinceField: "FPROVINCE",
              cityField: "FCITY",
              districtField: "FCOUNTY",
            },
          },
          {
            name: "FPROVINCE",
          },
          {
            name: "FCITY",
          },
          {
            name: "FCOUNTY",
          },
          {
            name: "FADDRESS",
          },
          {
            name: "FDELIVERYAMOUNT",
            props: {
              min: 0,
              format: "￥0.00",
              precision: 2,
            },
          },
          {
            name: "FNOTE",
            colspan: 2,
            props: {
              type: "textarea",
            },
          },
        ],
      },
      //查询面板配置
      queryPanel: {
        fields: [
          {
            element: "el-input",
            label: "门店名称",
            name: "FDESC",
          },
          {
            element: "el-input",
            label: "电话",
            name: "FTEL",
          },
        ],
      },
      //数据集配置
      datasetCfg: datasetCfg,
      total: 100,
    };
  },
  model: {
    prop: "value",
    event: "valuechange",
  },
  props: {
    value: {
      type: Object,
    },
  },

  computed: {},
  watch: {},
  methods: {
    /*   showAdd() {
      this.detailFormVisible = true;
      this.editstate = "add";
      this.detailTitle = "添加门店";
      this.editData = this.dataset.createEmptyData();
    }, */
    showEdit(data) {
      this.dataset.curRecord = data.row;
      this.editstate = "edit";
      this.detailTitle = "编辑门店-" + this.dataset.curRecord.FDESC || "";
      this.detailFormVisible = true;
      this.editData = Object.assign({}, this.dataset.curRecord);
    },
    /*   remove(data) {
      this.$confirm("确定要删除【" + data.row.FDESC + "】", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let saveHelper = this.createSaveHelper(this.dataset.modelFile);
          saveHelper.remove(data.row);
          saveHelper.save().then((res) => {
            this.dataset.reload();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {}); 
    },*/
    save() {
      let _result;
      this.$refs.detailForm.validate((result) => {
        _result = result;
      });
      if (!_result) return;
      if (this.editstate == "edit") {
        let curModel = this.dataset.getCurModel();
        curModel.set(this.editData);
      } else {
        this.dataset.add(this.editData);
      }

      if (this.dataset.getDirty()) {
        let promise = this.dataset.save();
        promise.then((res) => {
          this.detailFormVisible = false;
          this.$message({
            message: "保存成功",
            type: "success",
          });
        });
      } else {
        this.detailFormVisible = false;
      }
    },
    /*   afterquery() {
      this.dataset.load();
    }, */
  },
  mounted() {
    this.datasetCfg.aliasName = "dataset";
    this.dsConfigs = [this.datasetCfg];
    this.dataBridge.set(this.datasetCfg.aliasName, ["detailForm"]);
    
    // this.dataset = this.createDataSet(this.datasetCfg);
    // this.dsConfigs = [this.datasetCfg];
    // this.dataBridge.set(this.dataset, ["dataTable", "detailForm"]);
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scope>
</style>

